//
//  L0AlertEditor.m
//  Alerts Editor
//
//  Created by ∞ on 22/12/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "L0AlertEditor.h"
#import "L0AlertDocument.h"

@implementation L0AlertEditor

- (IBAction) massExportOfStrings:(id) sender {
	NSOpenPanel* open = [NSOpenPanel openPanel];
	[open setMessage:@"Choose any number of alert files to be exported:"];
	[open setPrompt:@"Choose"];
	[open setRequiredFileType:@"alert"];
	[open setAllowsMultipleSelection:YES];
	
	if ([open runModal] == NSCancelButton) return;
	
	NSArray* arr = [[[open filenames] copy] autorelease];
	
	open = [NSOpenPanel openPanel];
	[open setMessage:@"Choose where to export the new strings files:"];
	[open setPrompt:@"Export"];
	[open setCanChooseFiles:NO];
	[open setCanChooseDirectories:YES];
	
	if ([open runModal] == NSCancelButton) return;
	
	for (NSString* path in arr) {
		NSError* err = nil;
		L0AlertDocument* doc;
		do {
			doc = [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:[NSURL fileURLWithPath:path] display:YES error:&err];
			if (err && ![NSApp presentError:err]) return;
		} while (err != nil);
		
		NSString* target = [[open filename] stringByAppendingPathComponent:[[[path lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"strings"]];
		if ([doc exportStringsWithUserInteraction:target])
			[doc close];
	}
}
	
@end
